package com.algorithm;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.TreeSet;

/**
 * @Auther: zwg
 * @Date: 2019/1/17 14:46
 * @Description:
 */
public class AlgorithmTest1 {
    @Test
    public void removeDuplicates() {
        //给定一个数组，在不扩展新数组的前提下算出去重后的数组大下
        int[] nums = {1, 1, 2,2,2,2,2,3,3,3,3,3,3,3,4,5,6};
        System.out.println("修改之前：");
        for (int num : nums) {
            System.out.print(num);
        }
        nums = AlgorithmTest2.xxx(nums);
        System.out.println();
        System.out.println("处理后：");
        for (int num : nums) {
            System.out.print(num);
        }

    }


    public static void main(String[] args) {
        AlgorithmTest1 lt = new AlgorithmTest1();
        Integer []nums = {0,1,1,1,1,1,1,2,2,3,3,4};
        List<Integer> integerList = Arrays.asList(nums);
        TreeSet treeSet = new TreeSet();
        integerList.forEach(n -> treeSet.add(n));
        for (Object o : treeSet) {
            System.out.print(o);
        }

    }

    // 扔进去AC了他
    public int removeDuplicates(int[] nums) {
        if (nums.length == 0)
            return 0;
        //判断无输入
        int number = 0;//标记计数
        for (int i=0; i < nums.length ; i++) {
            if ( nums[i] != nums[number] ) {
                number++;
                nums[number] = nums[i];
            }
        }
        number+=1; //标记+1即为数字个数
        return number;
    }
}
